package goodbaby.dklt.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.classic.core.fragment.BaseFragment;

import goodbaby.dklt.GbbPreferences;
import goodbaby.dklt.R;

/**
 * Created by Jayden on 2016/4/19 14:02.
 *
 * @version V1.0
 * @Title: StudyFragment
 * @Description: 班级页面
 */
public class StudyFragment extends BaseFragment {
    public static int fromAttendance = 0;
    public static int fromCourse = 2;
    public static int fromLeave = 1;
    public static int fromRecipe = 3;
    public boolean shouldLoadData = false;
    private TextView tvTitle;
    private ClassFragment mClassFragment;
    private ClassGridFragment mClassGridFragment;

    public int getLayoutResId() {
        return R.layout.fragment_study;
    }

    public void initData() {
        super.initData();
    }

    public void initView(View paramView) {
        super.initView(paramView);
        tvTitle = (TextView) paramView.findViewById(R.id.tv_common_title);
        tvTitle.setText("班级");

        loadData();
    }

    private void loadData(){
        //判断是否是园长
        String role = GbbPreferences.getRole();
        if("2".equals(role)){
            //园长
            if(mClassGridFragment == null){
                mClassGridFragment = new ClassGridFragment();
            }
            getFragmentManager().beginTransaction().replace(R.id.fl_content,mClassGridFragment).commit();
            mClassGridFragment.loadData();
        }else{
            //老师
            if(mClassFragment == null){
                mClassFragment = new ClassFragment();
            }
            getFragmentManager().beginTransaction().replace(R.id.fl_content, mClassFragment).commit();
            mClassFragment.loadData(GbbPreferences.getClassId());
        }

    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        return super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);
    }

    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser && shouldLoadData){
            shouldLoadData = false;
            loadData();
        }
    }
}
